<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *任务记录
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['tasktitle'])){
		$params['tasktitle like']='%'.trim($_RQ['tasktitle']).'%';
		$return['params']['tasktitle']=$_RQ['tasktitle'];
	} 
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_inclock_task_record',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['status']='进度:'.$item['task_progress'].'/'.$item['task_demand'];
			$item['finishtime']=$item['finishtime']=='0000-00-00 00:00:00'?' ':$item['finishtime'];
			$item['member']=cfc('core')->member_show($item['mid']);
			$isadd=pdo_get('jy_inclock_task_record_log',array('mid'=>$item['mid'],'status'=>0));
			$item['isadd']=$isadd['id']?1:0;
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'参与列表'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'tasktitle','title'=>'任务名称','type'=>'string'),
			array('name'=>'tasktype','title'=>'任务类型','type'=>'radio','options'=>'tasktype'),
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'picktime','title'=>'领取时间','type'=>'string'),
			array('name'=>'finishtime','title'=>'完成时间','type'=>'time'),
			array('name'=>'isadd','title'=>'有待审核？','type'=>'radio','options'=>'isadd'),
			array('name'=>'status','title'=>'任务状态','type'=>'string'),
		),'action'=>array(
			array('op'=>'log','title'=>'打卡记录','type'=>'href'),
		)),
		'search'=>array(
			array('name'=>'tasktitle','title'=>'任务名称','type'=>'string','width'=>'40'),
		)
	);
	$return['isadd']=array('无需审核','需要审核');
	$return['tasktype']=$this->task_types;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='log'){
	$record_id=intval($_RQ['id']);
	$params=array('uniacid'=>$_SESSION['uniacid'],'record_id'=>$record_id);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_inclock_task_record_log',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回参与列表'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'intime','title'=>'提交时间','type'=>'time'),
			array('name'=>'finishtime','title'=>'完成时间','type'=>'time'),
			array('name'=>'status','title'=>'任务状态','type'=>'radio','options'=>'status_types'),
		),'action'=>array(
			array('op'=>'check','title'=>'审核','type'=>'modal'),
		)),
		'search'=>array(
			array('name'=>'tasktitle','title'=>'任务名称','type'=>'string','width'=>'40'),
		)
	);
	$return['status_types']=$this->status_types;
	$return['tasktype']=$this->task_types;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='check'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$logid=intval($post['id']);
		$status=intval($post['status']);
		if(!$status){
			exi('请选择审核通过还是不通过！','error');
		}
		$this->model('model')->checklog($logid,$status,$post['msg']);
		exi('处理成功！','','log');
	}
	$item=$this->get('task_record_log',array('id'=>intval($_RQ['id'])));
	if(!$item){
		exi('指定记录不存在！','error');
	}
	$item['images']=json_decode($item['images'],true);
	$item['lat_lng']=json_decode($item['lat_lng'],true);
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'审核打卡',
		'edit'=>array(
			array('name'=>'images','title'=>'打卡照片','type'=>'images'),
			array('name'=>'lat_lng','title'=>'打卡坐标','type'=>'lat_lng','show'=>array('type'=>2)),
			array('name'=>'status','title'=>'审核','type'=>'radio','options'=>'status_types'),
			array('name'=>'msg','title'=>'不通过原因','type'=>'text','show'=>array('status'=>2)),
		),
	);
	$return['status_types']=$this->status_types;
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_inclock_task_record',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
